﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Controller
{
    public class TreeCtr
    {
       
        private List<TreeNode> treeNodes;
        private static TreeCtr instance;
        
        private TreeCtr(string nodeName)
        {
            
            treeNodes = new List<TreeNode>();
        }
        public static TreeCtr GetInstance(string nodeName)
        {
            if (instance == null)
            {
                instance = new TreeCtr(nodeName);
            }
            return instance;
        }

        public void AddTreeNode(TreeNode treeNode)
        {
         
            treeNodes.Add(treeNode);
            
        }

        public void AddAsChild(TreeNode parent, TreeNode child)
        {
            //FindTreeNode(parent).Nodes.Add(child);
       
            

        }



        public List<TreeNode> GetAllTreeNodes()
        {
            return treeNodes;
        }
        
        public TreeNode FindTreeNode(TreeNode tn)
        {
            bool found = false;
            int index = 0;
            while(!found && index < treeNodes.Count)
            {
                if (tn.Equals(treeNodes[index]))
                {
                    found = true;
                }
                else
                {
                    index++;
                }
            }

            if (found)
            {
                return treeNodes[index];
            }
            else
            {
                return null;
            }

           

        }



    }
}
